<template>
  <div class="login">
    <div class="box">
      <el-form :model="loginForm" :rules="rules" ref="loginForm">
        <el-form-item prop="userName">
          <el-input
            placeholder="请输入用户名"
            prefix-icon="el-icon-user-solid"
            v-model="loginForm.userName"
          >
          </el-input>
        </el-form-item>
        <el-form-item prop="paw">
          <el-input
            placeholder="请输入密码"
            prefix-icon="el-icon-lock"
            v-model="loginForm.paw"
            show-password
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-row type="flex" justify="end"
            ><el-button type="primary" @click="loginBtn('loginForm')"
              >登录</el-button
            >
          </el-row>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { menuJson } from "@/views/system/menu/menuJson"
export default {
  data() {
    return {
      loginForm: {},
      rules: {
        userName: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        paw: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      routeList: [],
    }
  },
  mounted() {},
  methods: {
    loginBtn(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log("成功")
          this.putRoute(menuJson)
          this.$store.commit("setRouteTree", menuJson)
          console.log(this.routeList)
          this.$store.commit("setRoute", this.routeList)
          this.$router.push({ path: "/" })
        }
      })
    },
    putRoute(arr) {
      if (arr && arr.length > 0) {
        arr.map((item) => {
          if (item.children && item.children.length > 0) {
            let bb = { ...item }
            this.routeList.push(bb)
            this.putRoute(item.children)
          } else {
            let aa = { ...item }
            this.routeList.push(aa)
            return false
          }
        })
      }
    },
  },
}
</script>
<style scoped lang="scss">
.login {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;

  .box {
    width: 400px;
    height: auto;
    box-shadow: 0 0 5px #ccc;
    padding: 20px;
  }
}
</style>
